﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TransformBLG
{
    /// <summary>
    /// Interaction logic for LoadingPanel.xaml
    /// </summary>
    public partial class LoadingPanel : UserControl
    {
        private LoadingPanelDisplayType _displayType = default(LoadingPanelDisplayType);
        public event EventHandler OnYesClick;
        public event EventHandler OnNoClick;
        public event EventHandler OnOKClick;

        /// <summary>
        /// Gets or sets the display text.
        /// </summary>
        /// <value>
        /// The display text.
        /// </value>
        public string DisplayText
        {
            get { return (string)this.lblDisplayText.Content; }
            set { this.lblDisplayText.Content = value; }
        }

        /// <summary>
        /// Gets or sets the display type.
        /// </summary>
        /// <value>
        /// The display type.
        /// </value>
        public LoadingPanelDisplayType DisplayType
        {
            get { return this._displayType; }
            set { this._displayType = value; changeDisplayType(this._displayType); }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="LoadingPanel"/> class.
        /// </summary>
        public LoadingPanel()
        {
            InitializeComponent();
            this.DisplayType = LoadingPanelDisplayType.LoadingScreen;
        }




        /// <summary>
        /// Changes the display type.
        /// </summary>
        /// <param name="displayType">The display type.</param>
        private void changeDisplayType(LoadingPanelDisplayType displayType)
        {

            switch(displayType)
            {
                case LoadingPanelDisplayType.OK:
                    {
                        this.btnNo.Visibility = System.Windows.Visibility.Hidden;
                        this.btnYes.Visibility = System.Windows.Visibility.Hidden;
                        this.loadingAnimation.Visibility = System.Windows.Visibility.Hidden;
                        this.btnOK.Visibility = System.Windows.Visibility.Visible;

                        break;
                    }
                case LoadingPanelDisplayType.YesNo:
                    {
                        this.btnNo.Visibility = System.Windows.Visibility.Visible;
                        this.btnYes.Visibility = System.Windows.Visibility.Visible;
                        this.loadingAnimation.Visibility = System.Windows.Visibility.Hidden;
                        this.btnOK.Visibility = System.Windows.Visibility.Hidden;
                        break;
                    }
                case LoadingPanelDisplayType.LoadingScreen:
                default:
                    {
                        this.btnNo.Visibility = System.Windows.Visibility.Hidden;
                        this.btnYes.Visibility = System.Windows.Visibility.Hidden;
                        this.loadingAnimation.Visibility = System.Windows.Visibility.Visible;
                        this.btnOK.Visibility = System.Windows.Visibility.Hidden;
                        break;
                    }
            }

        }

        /// <summary>
        /// Handles the Click event of the btnYes control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btnYes_Click(object sender, RoutedEventArgs e)
        {
            if(this.OnYesClick != null)
            {
                this.OnYesClick(this, new EventArgs());
            }
        }

        /// <summary>
        /// Handles the Click event of the btnOK control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (this.OnOKClick != null)
            {
                this.OnOKClick(this, new EventArgs());
            }
        }

        /// <summary>
        /// Handles the Click event of the btnNo control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btnNo_Click(object sender, RoutedEventArgs e)
        {
            if (this.OnNoClick != null)
            {
                this.OnNoClick(this, new EventArgs());
            }
        }
    }

    public enum LoadingPanelDisplayType
    {
        LoadingScreen,
        YesNo,
        OK
    }
}
